package com.zygh.interactiveplatform.module.controller;


import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.zygh.interactiveplatform.common.anno.PcLog;
import com.zygh.interactiveplatform.common.constant.SwaggerTagConst;
import com.zygh.interactiveplatform.module.entity.Operation;
import com.zygh.interactiveplatform.module.entity.vo.MonitorVO;
import com.zygh.interactiveplatform.module.service.CpuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 服务器监控
 *
 * @author ms
 * @since 20200401
 */
@Slf4j
@RestController
@RequestMapping("/cpu")
@Api(tags = {SwaggerTagConst.Admin.MANAGER_CPU_MONITOR})
public class CpuController {

    @Resource
    private CpuService cpuService;

    private String URL1 = "http://41.5.113.62:8099/cpu/getcpu";
    private String URL2 = "http://41.5.113.59:8099/cpu/getcpu";


    @ApiOperation(value = "监控CPU信息", notes = "监控信息")
    @GetMapping("/getcpu")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_CPU_MONITOR, content = "监控CPU信息")
    public Object getcpu() throws Exception {
        Map<String, Object> map = new HashMap<>();
        List<Object> list = new ArrayList<>();
        String cpu1 = HttpUtil.get(URL1);
        String cpu2 = HttpUtil.get(URL2);
        MonitorVO info = cpuService.info();
        map.put("cpu",info.getCpu());
        map.put("memory",info.getMemory());
        map.put("disk",info.getDisk());
        list.add(cpu1);
        list.add(cpu2);
        list.add(map);
        JSONArray jsonArray = JSONArray.fromObject(list);
        return jsonArray;
        //return cpuService.info();
    }


}
